#ifndef SIGNWAY_DEQUE_H
#define SIGNWAY_DEQUE_H
#include <stdint.h>
#include <stdio.h>

#ifndef __cplusplus
#define nullptr NULL
#define bool int 
#define true 1
#define false 0
#define new(type, ...) ({\
    type* __t = (type*) malloc(sizeof(type));\
    *__t = (type){__VA_ARGS__};\
    __t; })
#endif

typedef long long int value_type;
typedef value_type* pointer;
typedef pointer* map_pointer;

typedef struct deque_iterator {
    value_type* cur;
    value_type* first;
    value_type* last;
    map_pointer node;
} deque_iterator;

typedef struct deque {
    map_pointer map;
    uint32_t map_size;
    uint32_t pointer_size;/* 每一块包含节点个数 */
    deque_iterator start;/* 首个节点 */
    deque_iterator finish;/* 最后一个节点 */
} deque;

deque* deque_init();
void deque_destroy(deque* deq);
deque_iterator deque_start(deque* deq);
deque_iterator deque_finish(deque* deq);
void deque_push_front(deque* deq, value_type value);
void deque_push_back(deque* deq, value_type value);
void deque_foreach(deque* deq);/* 遍历输出 */

#endif /* SIGNWAY_DEQUE_H */
